<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GroupGood;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GroupGoodController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new GroupGood(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('group_id','团长id');
            $grid->column('goods_id');
            $grid->column('type_id');
            $grid->column('goods_image')->image('',100,100);
            $grid->column('goods_content');
            $grid->column('original_price');
            $grid->column('group_price');
            $grid->column('group_size');
            $grid->column('partake_size');
            $grid->column('end_time');
            $grid->column('group_status')->switch('', true);
            $grid->column('activion_status');
            $grid->activion_status
                ->using([1 => '进行中', 0 => '已结束'])
                ->dot(
                    [
                        1 => 'success',
                        0 => 'danger',
                    ],
                    'primary' // 默认颜色
                );
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new GroupGood(), function (Show $show) {
            $show->field('id');
            $show->field('group_id');
            $show->field('goods_id');
            $show->field('type_id');
            $show->field('goods_image');
            $show->field('goods_content');
            $show->field('original_price');
            $show->field('group_price');
            $show->field('group_size');
            $show->field('partake_size');
            $show->field('end_time');
            $show->field('group_status');
            $show->field('activion_status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new GroupGood(), function (Form $form) {
            $form->display('id');
            $form->text('group_id');
            $form->text('goods_id');
            $form->text('type_id');
            $form->text('goods_image');
            $form->text('goods_content');
            $form->text('original_price');
            $form->text('group_price');
            $form->text('group_size');
            $form->text('partake_size');
            $form->text('end_time');
            $form->text('group_status');
            $form->text('activion_status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
